
package com.alex.web.service.impl;

import com.alex.web.db.domain.PageInfo;
import com.alex.web.db.domain.PageControl;
import com.alex.web.bean.member.Permission;
import com.alex.web.service.PermissionService;
import com.alex.web.dao.PermissionDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 *
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;
	/**
	 * 根据实体Permission，新增 信息
	 * 返回影响行数
	 */
    public Integer insertPermission(Permission permission){
    	//判断传入的Permission是否为空
		if (permission == null) {
			return 0;
		}
		//执行新增操作，具体请看 PermissionMapper.xml
		Integer i = permissionDao.insert(permission);
		return i;
    }
	/**
	 * 根据实体Permission，更新 信息，用主键更新
	 * 返回影响行数
	 */
    public Integer updatePermission(Permission permission){
		//判断传入的Permission是否为空
		if (permission == null) {
			return 0;
		}
		//执行更新操作，具体请看 PermissionMapper.xml
		Integer i = permissionDao.update(permission);
		return i;
    }
	/**
	 * 分页查询
	 */
    public PageControl<Permission> page(Permission permission, PageInfo pageInfo, String whereSql, String orderSql){
		return permissionDao.getPageByObj(permission, pageInfo, whereSql, orderSql);
    }
	/**
	 * 根据主键id，查询一个实体Permission
	 * 返回实体Permission
	 */
    public Permission find(Integer id){
		return permissionDao.getEntityById(id);
    }
	/**
	 * 根据主键id
	 * 返回影响行数
	 */
    public Integer delete(Integer id){
		//真正的删除了
		return permissionDao.delete(id);
    }


	public List<Permission> findPermsByRoleId(Integer rid){
    	return permissionDao.getListByObj(new Permission(),"id in (select permit_id from role_permission where role_id = "+rid+")");
	}


    

}
